/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.google.common.base.Joiner;
/*     */ import com.zimbra.cs.db.DbPool;
/*     */ import com.zimbra.cs.db.DbPool.DbConnection;
/*     */ import com.zimbra.cs.db.StatTrackingPreparedStatement;
/*     */ import com.zimbra.cs.stats.ActivityTracker;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import org.junit.After;
/*     */ import org.junit.Assert;
/*     */ import org.junit.Before;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestSqlStats
/*     */ {
/*  44 */   ActivityTracker tracker = new ActivityTracker("sql_test.csv");
/*     */   DbPool.DbConnection conn;
/*     */   
/*     */   @Before
/*     */   public void startup() throws Exception {
/*  49 */     DbPool.startup();
/*  50 */     this.conn = DbPool.getConnection();
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void test() throws Exception
/*     */   {
/*  56 */     StatTrackingPreparedStatement create = (StatTrackingPreparedStatement)this.conn.prepareStatement("CREATE TABLE stats_test(col1 INTEGER)");
/*  57 */     create.setTracker(this.tracker);
/*  58 */     create.execute();
/*     */     
/*     */ 
/*  61 */     StatTrackingPreparedStatement insert = (StatTrackingPreparedStatement)this.conn.prepareStatement("INSERT INTO stats_test(col1) VALUES(?)");
/*  62 */     insert.setInt(1, 1);
/*  63 */     insert.setTracker(this.tracker);
/*  64 */     insert.execute();
/*     */     
/*     */ 
/*  67 */     StatTrackingPreparedStatement select = (StatTrackingPreparedStatement)this.conn.prepareStatement("SELECT * FROM stats_test");
/*  68 */     select.setTracker(this.tracker);
/*  69 */     select.execute();
/*     */     
/*     */ 
/*  72 */     StatTrackingPreparedStatement update = (StatTrackingPreparedStatement)this.conn.prepareStatement("UPDATE stats_test SET col1 = ?");
/*  73 */     update.setInt(1, 10);
/*  74 */     update.setTracker(this.tracker);
/*  75 */     update.execute();
/*     */     
/*     */ 
/*  78 */     StatTrackingPreparedStatement delete = (StatTrackingPreparedStatement)this.conn.prepareStatement("DELETE FROM stats_test");
/*  79 */     delete.setTracker(this.tracker);
/*  80 */     delete.execute();
/*     */     
/*     */ 
/*  83 */     StatTrackingPreparedStatement drop = (StatTrackingPreparedStatement)this.conn.prepareStatement("DROP TABLE stats_test");
/*  84 */     drop.setTracker(this.tracker);
/*  85 */     drop.execute();
/*     */     
/*     */ 
/*  88 */     ArrayList<String> datalines = (ArrayList)this.tracker.getDataLines();
/*     */     
/*     */ 
/*  91 */     ArrayList<String> results = new ArrayList();
/*  92 */     for (String line : datalines) {
/*  93 */       results.add(Joiner.on(",").join(Arrays.asList(line.split(",")).subList(0, 2)));
/*     */     }
/*     */     
/*  96 */     Collections.sort(results);
/*     */     
/*     */ 
/*  99 */     List<String> expected = Arrays.asList(new String[] { "DELETE,1", "INSERT,1", "SELECT,1", "UPDATE,1", "other,2" });
/* 100 */     Assert.assertEquals(expected, results);
/*     */   }
/*     */   
/*     */   @After
/*     */   public void shutdown()
/*     */     throws Exception
/*     */   {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestSqlStats.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */